package study.mybatis.main;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import study.mybatis.po.User;

public class Main {
	public  static void main(String[] args) throws IOException{
		String resource = "study/mybatis/main/Configuration.xml";
		Reader reader = Resources.getResourceAsReader(resource);
		SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
		SqlSession session1 = factory.openSession(true);
		SqlSession session2 = factory.openSession(true);
		try{
//			User user = new User();
//			List l = session.selectList("users.selectUsers", user,new RowBounds(2, 1));
//			System.out.println(l);
			
			User user = (User)session1.selectOne("users.getUserById", 1);
			System.out.println(user.getName());
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		finally{
//			session1.close();
		}
		
		try{
			
//			User user = new User();
//			user.setId(3);
//			user.setName("hello");
//			session1.insert("users.addUser", user);
		}catch(Exception ex){
			ex.printStackTrace();
		}
		finally{
			session1.close();
		}
		
		
		try{
			
			User user = (User)session2.selectOne("users.getUserById", 1);
			System.out.println(user.getName());
			
		}catch(Exception ex){
			ex.printStackTrace();
		}
		finally{
			session2.close();
		}
		
		
	}

}
